package canglang.monitor.cases.service.impl;

import canglang.monitor.cases.dao.CaseFiveDAO;
import canglang.monitor.cases.model.CaseFiveModel;
import canglang.monitor.cases.model.CaseLightModel;
import canglang.monitor.cases.service.CaseFiveMgr;
import canglang.monitor.cases.service.CaseLightMgr;
import canglang.monitor.cases.to.SearchFiveTO;
import canglang.monitor.core.base.pagination.PaginatedListHelper;
import canglang.monitor.core.base.util.DateUtil;

import java.util.List;
import java.util.Date;

public class CaseFiveMgrImpl implements CaseFiveMgr {

    private CaseFiveDAO caseFiveDAO;

    private CaseLightMgr caseLightMgr;

    public void setCaseLightMgr(CaseLightMgr caseLightMgr) {
        this.caseLightMgr = caseLightMgr;
    }

    public void setCaseFiveDAO(CaseFiveDAO caseFiveDAO) {
        this.caseFiveDAO = caseFiveDAO;
    }

    public CaseFiveModel addCaseFive(CaseFiveModel caseFiveModel) {
        int id = caseFiveDAO.addCaseFive(caseFiveModel);
        CaseLightModel caseLightModel = new CaseLightModel();
        caseLightModel.setCaseType("05");
        caseLightModel.setCaseId(id);
        caseLightModel.setDeptId(caseFiveModel.getDeptId());
        caseLightModel.setPplInd(caseFiveModel.getPplInd());
        caseLightModel.setProcInd(caseFiveModel.getProcInd());
        caseLightModel.setLightInd("N");
        Date date = DateUtil.getDate();
        caseLightModel.setCreateId(caseFiveModel.getCreateId());
        caseLightModel.setUpdateId(caseFiveModel.getCreateId());
        caseLightModel.setCreateDt(date);
        caseLightModel.setUpdateDt(date);
        caseLightMgr.addCaseLight(caseLightModel);
        return caseFiveDAO.getCaseFive(id);
    }

    public CaseFiveModel getCaseFive(int caseFiveId) {
        return caseFiveDAO.getCaseFive(caseFiveId);
    }

    public CaseFiveModel saveCaseFive(CaseFiveModel caseFiveModel) {
        caseLightMgr.updateCaseFivePplLight(caseFiveModel.getCaseFiveId(),caseFiveModel.getPplInd(),caseFiveModel.getUpdateId());
        caseLightMgr.updateCaseFiveProcLight(caseFiveModel.getCaseFiveId(),caseFiveModel.getProcInd(),caseFiveModel.getUpdateId());
        caseFiveModel = caseFiveDAO.saveCaseFive(caseFiveModel);
        caseLightMgr.updateLightDept("05",caseFiveModel.getCaseFiveId(),caseFiveModel.getDeptId());
        return caseFiveModel;
    }

    public void deleteCaseFive(int caseFiveId) {
        caseLightMgr.deleteUnuseLight("05",caseFiveId);
        caseFiveDAO.deleteCaseFive(caseFiveId);
    }

    public PaginatedListHelper search(PaginatedListHelper helper, SearchFiveTO searchTO) {
        int count = caseFiveDAO.searchCount(searchTO);
        helper.setFullListSize(count);
        List list = caseFiveDAO.searchList(helper, searchTO);
        helper.setList(list);
        return helper;
    }

    public List getCaseFiveList(SearchFiveTO searchTO) {
        return caseFiveDAO.getCaseFiveList(searchTO);
    }
}
